package com.example.myowntodo.fet_xhttpdemo.manager

import com.example.myowntodo.fet_xhttpdemo.entity.User


class TokenManager private constructor() {
    var token: String = ""
        private set

    var sign: String = ""
        private set

    /**
     * 当前登录的用户
     */
    var loginUser: User? = null
        private set

    fun setToken(token: String): TokenManager {
        this.token = token
        return this
    }

    fun setSign(sign: String): TokenManager {
        this.sign = sign
        return this
    }

    val isUserLogined: Boolean
        get() = loginUser != null

    fun setLoginUser(loginUser: User?): TokenManager {
        this.loginUser = loginUser
        return this
    }

    companion object {
        private var sInstance: TokenManager? = null

        val instance: TokenManager?
            get() {
                if (sInstance == null) {
                    synchronized(TokenManager::class.java) {
                        if (sInstance == null) {
                            sInstance = TokenManager()
                        }
                    }
                }
                return sInstance
            }
    }
}